package hammersmith.local.management;

import hammersmith.local.valueobjects.Employee;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * EmployeeManagement-Klasse
 * 
 * @author hammersmith
 *
 */
public class EmployeeManagement implements Serializable{

	private static final long serialVersionUID = 6497027709348099596L;
	
	private ArrayList<Employee> employeeList;

	public EmployeeManagement(){
		employeeList=new ArrayList<Employee>();
	}

	public ArrayList<Employee> getEmployeeList() {
		return employeeList;
	}
	
	/**
	 * 
	 * Methode zum einloggen in das Mitarbeiter-Menue
	 * 
	 * @param user
	 * @param pw
	 * @return
	 */
	public Employee loginAsEmployee(String user, String pw){
		ArrayList<Employee> employeeList = this.employeeList;

		int userAsInt=04;
		
		try {
			userAsInt = Integer.parseInt(user);
		} catch (NumberFormatException e) {
			//e.printStackTrace();
		}

		//Durchlauf der aktuellen Mitarbeiterliste und abgleichen mit den Eingaben
		for (Employee employee : employeeList) {
			if (userAsInt == employee.getEmployeeId()) {
				if (pw.equals(employee.getPassword())) {
					return employee;
				} else {
					return null;
				}
			} else {
				return null;
			}
		}
		return null;
	}
	
	
	public void setEmployeeList(ArrayList<Employee> employeeList) {
		this.employeeList = employeeList;
	}
}
